/**
 * @file flash_if.h
 * @brief Flash interface header file
 */

#ifndef __FLASH_IF_H__
#define __FLASH_IF_H__

#include "stm32f10x.h"


#define USER_FLASH_LAST_PAGE_ADDRESS 	(uint32_t)0x0800F800	// 用户 Flash 最后一页地址
#define USER_FLASH_END_ADDRESS 			(uint32_t)0x08010000 	// 用户 Flash 结束地址
#define FLASH_PAGE_SIZE 				(0x400) 				// 每页大小为 1KB

#define APPLICATION_ADDRESS 			(uint32_t)0x08003000 	// 用户应用程序起始地址

#define FLASH_PAGE_NUMBER  				(uint32_t)((APPLICATION_ADDRESS - 0x08000000) >> 12)	// 获取将加载用户程序的扇区号

#define FLASH_PROTECTED_PAGES   		((uint32_t)~((1 << FLASH_PAGE_NUMBER) - 1))				// 计算掩码以测试将加载用户程序的闪存是否受到写保护

#define USER_FLASH_SIZE  				(USER_FLASH_END_ADDRESS - APPLICATION_ADDRESS)			// 定义用户程序大小

void FLASH_If_Init(void);
uint32_t FALSH_If_GetWriteProtectionStatus(void);
uint8_t FALSH_If_DisableWriteProtection(void);
uint32_t FLASH_If_Erase(uint32_t start_sector);
uint32_t FLASH_If_Write(__IO uint32_t* flash_address, uint32_t* data, uint16_t data_length);

#endif /* __FLASH_IF_H__ */
